home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.07 Jul 91 / MacLock 1.0 / CMacLockPane.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-27  |  2.5 KB  |  125 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * FILE:        CMacLockPane.c
  3.  * Programmer:    Mark Bykerk Kauffman
  4.  *                Copyright © 1990.
  5.  * Date:        1/91
  6.  * Purpose:
  7.  *        Pane methods for MacLock.
  8.  * PARENTCLASS = CStarterPane    
  9.  *
  10.  *****/
  11.  
  12. #include <string.h> 
  13. #include "CMacLockPane.h"
  14. #include "CPassword.h"
  15.  
  16. /* Global Variables used by objects of this class. */
  17. /*    commands    */
  18. #define        LockIt        5000
  19.  
  20. /*    resource IDs    */
  21. #define        ButtonID1    2047
  22. #define        openLockRsrc    2049
  23. #define        closedLockRsrc    2050
  24.  
  25. /* The single password object global to the application. */
  26. extern         CPassword    *gThePassword; 
  27.  
  28. /* METHOD IMPLEMENTATIONS */
  29.  
  30. /*****
  31.  * IMacLockPane
  32.  *
  33.  *    MacLockPane's initialization method.
  34.  *    Setup the lock's location for the Draw method, get the icons from the
  35.  *    resource table, initialize the window the lock is displayed in,
  36.  *    and create a button object.
  37.  *
  38.  *****/
  39. void CMacLockPane::IMacLockPane(CView *anEnclosure, CBureaucrat *aSupervisor,
  40.                             short aWidth, short aHeight,
  41.                             short aHEncl, short aVEncl,
  42.                             SizingOption aHSizing, SizingOption aVSizing)
  43. {
  44.     SetRect(&LockLocation,10,10,74,74);
  45.  
  46.     openLockIcon = GetIcon(openLockRsrc);
  47.     closedLockIcon = GetIcon(closedLockRsrc);
  48.     displayedIcon = openLockIcon;
  49.     CPanorama::IPanorama(anEnclosure, aSupervisor, aWidth, aHeight,
  50.                             aHEncl, aVEncl, aHSizing, aVSizing);
  51.     LockButton = new(CButton);
  52.     LockButton->IButton(ButtonID1, this, this);
  53.     LockButton->SetClickCmd(LockIt);
  54.     SetWantsClicks(TRUE);
  55.  
  56. }
  57.  
  58. /*****
  59.  * Dispose
  60.  *
  61.  *    MacLockPane's dispose method.
  62.  *    Get rid of the lock button object then call the inherited dispose
  63.  *    method.
  64.  *
  65.  *****/
  66. void CMacLockPane::Dispose(void)
  67.  
  68. {
  69.     LockButton->Dispose();    
  70.     inherited::Dispose();
  71. }
  72.  
  73. /*****
  74.  * DoCommand
  75.  *
  76.  *    MacLockPane's DoCommand method.
  77.  *    When the lock button is pressed, display the closed lock icon and
  78.  *    wait for the password.  After the password is entered, display
  79.  *     the open lock icon.
  80.  *
  81.  *****/
  82. void CMacLockPane::DoCommand(long theCommand)
  83.  
  84. {
  85.     Rect    Location;
  86.     char    answer[255]="\0";
  87.  
  88.  
  89.     switch (theCommand) 
  90.     {
  91.         case LockIt:    this->Prepare();
  92.                         displayedIcon = closedLockIcon;
  93.                         SysBeep(20);
  94.                         Draw(&frame);  /* frame is an instance variable 
  95.                                           defined in CPane.
  96.                                         */              
  97.                         gThePassword->WaitForPassword();
  98.                         displayedIcon = openLockIcon;
  99.                         Draw(&frame);  
  100.                         break;
  101.  
  102.         default:        inherited::DoCommand(theCommand);
  103.                         break;
  104.     }
  105. }
  106.  
  107. /***
  108.  * Draw
  109.  *
  110.  *    MacLockPane's Draw method.
  111.  *    
  112.  *
  113.  ***/
  114. void CMacLockPane::Draw(Rect *area)
  115.  
  116. {    
  117.     Rect    Location;
  118.  
  119.     /* draw your stuff */
  120.     Location = this->LockLocation;
  121.     PlotIcon(&Location,displayedIcon);
  122. }
  123.  
  124.  
  125.